<template>
	<div style="padding:0px;">
		<el-card class="box-card">
		  <div slot="header" class="clearfix">
		    <span style="line-height: 30px;"  >活动专栏</span>
		  </div>
		  <div  class="text item">
			<el-form :model="dialogForm" :rules="rules" ref="dialogForm" :label-width="formLabelWidth">
				<el-form-item label="活动简介"  prop="pushComment">
			      <el-input  type="textarea" :rows=3 v-model="dialogForm.pushComment" auto-complete="off" :disabled="!dialogSendData.isAdd"></el-input>
			    </el-form-item>
			  	
			    <el-form-item label="链接网址"  prop="afterOpenUrl">
			      <el-input v-model="dialogForm.afterOpenUrl" auto-complete="off" :disabled="!dialogSendData.isAdd"></el-input>
			    </el-form-item>
			  </el-form>
			</div>
		</el-card>
		<div  style="text-align:right;margin-top:15px;">
			 <el-button @click="returnBack">返 回</el-button>
			 <el-button v-if="dialogSendData.isAdd" type="primary" @click="submitConfirmForm('dialogForm')">提 交</el-button>
		</div>
	</div>
</template>
<script>
    import agentHttp from '@/utils/agentHttp.js'
    import {require,prop} from '@/utils/rules.js'
	export default{
		components:{},
		created(){		
			if(this.dialogSendData.id!==""){
	      		//修改
	      		this.selectData(); 
	      	}
        },
		props:['dialogSendData','tableData'],
		data(){
			return{
				formLabelWidth:'170px',
				//弹窗或者查看页面信息
		         dialogForm:{
		          imagUrl:[],   //七牛图片地址
		          activityTheme:"",
		          linkUrl:""
		         
		        },
		        //验证规则
		        rules: {
		           'pushComment':[require('活动简介',{trigger:"blur"})],
		           'afterOpenUrl':[require('链接地址',{trigger:"blur"})],
		        }
			}
		},methods:{
			returnBack(){
				this.dialogSendData.dialogFormVisible=false;
			},
			submitConfirmForm(formName){
                this.$refs[formName].validate((valid) => {
		          if (valid) {
		          	if(this.dialogSendData.id===""){
		          		//添加
		          	    this.addData();
		          	}else{
		          		//修改
		          		this.editData();
		          	}
		          
		          } else {
		            this.$nextTick(()=>{
		          		this.$message.warning(document.getElementsByClassName('el-form-item__error')[0].innerText||"提交失败");
		                return false;
		          	})
		          }
		        });
			},
		    addData(){
		        agentHttp.postJson('adminApi/admin/push_operation_log/add_message',this.dialogForm).then((data)=>{
		            if(data.success){  
		            	this.$emit('refreshTableData', null);
		            	this.$message.success(data.data||"添加成功");
		                setTimeout(()=>{
	            		this.dialogSendData.dialogFormVisible=false;
	            	  },500)
		            } 
		        }) 
		    },
		    editData(){
		        agentHttp.putJson('adminApi/admin/push_operation_log/update_message',this.dialogForm).then((data)=>{
		            if(data.success){  
		            	this.$emit('refreshTableData', null);
		            	this.$message.success(data.data||"修改成功");
		                 setTimeout(()=>{
	            		this.dialogSendData.dialogFormVisible=false;
	            	  },500)
		            } 
		        }) 
		    },
		    selectData(){
		        agentHttp.get('adminApi/admin/push_operation_log/select_operation/'+this.dialogSendData.id).then((data)=>{	
		            if(data.success){  
		            	this.dialogForm=data.data;
		            } 
		        }) 
		    },

		}
	}
</script>